import axios from "axios";


// axios.defaults.baseURL = ''  //正式
// axios.defaults.baseURL = 'http://test' //测试

//post请求头
// axios.defaults.headers.post["Content-Type"] ="application/x-www-form-urlencoded;charset=UTF-8";
//设置超时
axios.defaults.timeout = 10000;

axios.interceptors.request.use(
    config => {
        return config;
    },
    error => {
        return Promise.reject(error);
    }
);

axios.interceptors.response.use(
    response => {
        if (response.status == 200) {
            return Promise.resolve(response);
        } else {
            return Promise.reject(response);
        }
    },
    error => {
        // alert(`异常请求：${JSON.stringify(error.message)}`)
        console.log("请求失败")
    }
);

const instance = axios.create({
    baseURL: 'http://localhost:8081/api/',
    timeout: 1000,
    headers: {'X-Custom-Header': 'foobar'}
});

export {instance}


